//
// Created by miaomiaole on 2023/5/16.
//

#ifndef CMAKECXX_WITHSTATIC_H
#define CMAKECXX_WITHSTATIC_H

#include <iostream>

using namespace std;

extern int x;

class WithStatic {
    static int x;
    static int y;
public:
    void print() const {
        cout << "WithStatic:: x" << x << endl;
        cout << "WithStatic:: y" << y << endl;
    }
};

class X_static {
    int i;
    static int j;
public:
    // 构造方法使用静态变量
    X_static(int ii = 0) : i(ii) {
        j = i;
    }

    int val() const {
        return i;
    }

    static int incr() {
        return ++j;
    }

    static int f_X_static() {
        return incr();
    }
};

class Egg {
    static Egg e;
    int i;

    Egg(int _i) : i(_i) {
        cout << "generate Egg is private" << endl;
    }

    Egg(const Egg &);

public:
    static Egg &instance() {
        return e;
    }

    /*// 静态方法不能重载
    static Egg *instance() {
        return &e;
    }*/

    int val() const {
        return i;
    }
};

extern WithStatic with_static;
extern WithStatic with;
#endif //CMAKECXX_WITHSTATIC_H
